Library

Correlation b/w dependent vars.(food loss and food waste)

# independent variables ----
deptData <- df %>%
  filter(.,is_closed == FALSE) %>%
  select(c(food_loss_kg,food_waste_kg,
           liquid_waste_kg,solid_waste_kg))

# correlation between independent variables ------------------------------------
deptData %>% cor_mat()
## # A tibble: 4 × 5
##   rowname         food_loss_kg food_waste_kg liquid_waste_kg solid_waste_kg
## * <chr>                  <dbl>         <dbl>           <dbl>          <dbl>
## 1 food_loss_kg           1             0.057           0.043          0.074
## 2 food_waste_kg          0.057         1               0.97           0.88 
## 3 liquid_waste_kg        0.043         0.97            1              0.73 
## 4 solid_waste_kg         0.074         0.88            0.73           1
# correlation p-values ---------------------------------------------------------
deptData %>% cor_pmat()
## # A tibble: 4 × 5
##   rowname         food_loss_kg food_waste_kg liquid_waste_kg solid_waste_kg
##   <chr>                  <dbl>         <dbl>           <dbl>          <dbl>
## 1 food_loss_kg           0         4.73e-  1       5.88e-  1       3.5 e- 1
## 2 food_waste_kg          0.473     0               9.85e-100       5.27e-52
## 3 liquid_waste_kg        0.588     9.85e-100       0               2.94e-28
## 4 solid_waste_kg         0.35      5.27e- 52       2.94e- 28       0
# visulalization
deptData %>%
  cor_mat() %>%
  cor_reorder() %>%
  pull_lower_triangle() %>%
  cor_plot(label = TRUE) 

Correlation b/w independent vars.

# independent variables ----
indeptData <- df %>%
  filter(.,is_closed == FALSE) %>%
  select(c(temp_c,humi_p, prcp_mm,
           fulls, halfs, takeouts,
           customers, liquors, sales))

# correlation between independent variables ------------------------------------
indeptData %>% cor_mat()
## # A tibble: 9 × 10
##   rowname   temp_c humi_p prcp_mm  fulls  halfs takeouts customers liquors sales
## * <chr>      <dbl>  <dbl>   <dbl>  <dbl>  <dbl>    <dbl>     <dbl>   <dbl> <dbl>
## 1 temp_c     1      0.094  -0.035  0.25   0.094    0.11      0.24    0.066  0.27
## 2 humi_p     0.094  1       0.35  -0.043 -0.15    -0.03     -0.065  -0.23  -0.11
## 3 prcp_mm   -0.035  0.35    1     -0.19  -0.097   -0.087    -0.16   -0.18  -0.16
## 4 fulls      0.25  -0.043  -0.19   1      0.33     0.15      0.92    0.33   0.8 
## 5 halfs      0.094 -0.15   -0.097  0.33   1        0.19      0.62    0.15   0.5 
## 6 takeouts   0.11  -0.03   -0.087  0.15   0.19     1         0.2     0.2    0.54
## 7 customers  0.24  -0.065  -0.16   0.92   0.62     0.2       1       0.32   0.84
## 8 liquors    0.066 -0.23   -0.18   0.33   0.15     0.2       0.32    1      0.46
## 9 sales      0.27  -0.11   -0.16   0.8    0.5      0.54      0.84    0.46   1
# correlation p-values ---------------------------------------------------------
indeptData %>% cor_pmat()
## # A tibble: 9 × 10
##   rowname   temp_c  humi_p prcp_mm    fulls    halfs takeouts customers  liquors
##   <chr>      <dbl>   <dbl>   <dbl>    <dbl>    <dbl>    <dbl>     <dbl>    <dbl>
## 1 temp_c   0       2.34e-1 6.57e-1 1.47e- 3 2.36e- 1 1.62e- 1  2.44e- 3 4.02e- 1
## 2 humi_p   2.34e-1 0       5.74e-6 5.85e- 1 5.28e- 2 7.07e- 1  4.1 e- 1 2.8 e- 3
## 3 prcp_mm  6.57e-1 5.74e-6 0       1.65e- 2 2.21e- 1 2.74e- 1  3.86e- 2 2.47e- 2
## 4 fulls    1.47e-3 5.85e-1 1.65e-2 0        1.58e- 5 6.14e- 2  4.63e-65 2.27e- 5
## 5 halfs    2.36e-1 5.28e-2 2.21e-1 1.58e- 5 0        1.35e- 2  1.07e-18 5.79e- 2
## 6 takeouts 1.62e-1 7.07e-1 2.74e-1 6.14e- 2 1.35e- 2 0         1.18e- 2 1.32e- 2
## 7 custome… 2.44e-3 4.1 e-1 3.86e-2 4.63e-65 1.07e-18 1.18e- 2  0        3.12e- 5
## 8 liquors  4.02e-1 2.8 e-3 2.47e-2 2.27e- 5 5.79e- 2 1.32e- 2  3.12e- 5 0       
## 9 sales    6.34e-4 1.74e-1 4.45e-2 6.76e-37 2.14e-11 9.41e-14  1.32e-44 5.46e-10
## # ℹ 1 more variable: sales <dbl>
# visulalization
indeptData %>%
  cor_mat() %>%
  cor_reorder() %>%
  pull_lower_triangle() %>%
  cor_plot(label = TRUE)

Correlation b/w independent vars.

# independent variables ----
indeptData <- df %>%
  filter(.,is_closed == FALSE) %>%
  select(c(temp_c,humi_p, prcp_mm,
           customers, liquors, sales))

# correlation between independent variables ------------------------------------
indeptData %>% cor_mat()
## # A tibble: 6 × 7
##   rowname   temp_c humi_p prcp_mm customers liquors sales
## * <chr>      <dbl>  <dbl>   <dbl>     <dbl>   <dbl> <dbl>
## 1 temp_c     1      0.094  -0.035     0.24    0.066  0.27
## 2 humi_p     0.094  1       0.35     -0.065  -0.23  -0.11
## 3 prcp_mm   -0.035  0.35    1        -0.16   -0.18  -0.16
## 4 customers  0.24  -0.065  -0.16      1       0.32   0.84
## 5 liquors    0.066 -0.23   -0.18      0.32    1      0.46
## 6 sales      0.27  -0.11   -0.16      0.84    0.46   1
# correlation p-values ---------------------------------------------------------
indeptData %>% cor_pmat()
## # A tibble: 6 × 7
##   rowname     temp_c     humi_p    prcp_mm customers  liquors    sales
##   <chr>        <dbl>      <dbl>      <dbl>     <dbl>    <dbl>    <dbl>
## 1 temp_c    0        0.234      0.657       2.44e- 3 4.02e- 1 6.34e- 4
## 2 humi_p    0.234    0          0.00000574  4.1 e- 1 2.8 e- 3 1.74e- 1
## 3 prcp_mm   0.657    0.00000574 0           3.86e- 2 2.47e- 2 4.45e- 2
## 4 customers 0.00244  0.41       0.0386      0        3.12e- 5 1.32e-44
## 5 liquors   0.402    0.0028     0.0247      3.12e- 5 0        5.46e-10
## 6 sales     0.000634 0.174      0.0445      1.32e-44 5.46e-10 0
# visulalization
indeptData %>%
  cor_mat() %>%
  cor_reorder() %>%
  pull_lower_triangle() %>%
  cor_plot(label = TRUE)

library(tidymodels)
## ── Attaching packages ────────────────────────────────────── tidymodels 1.1.1 ──
## ✔ broom        1.0.5     ✔ rsample      1.2.0
## ✔ dials        1.2.0     ✔ tune         1.1.2
## ✔ infer        1.0.5     ✔ workflows    1.1.3
## ✔ modeldata    1.2.0     ✔ workflowsets 1.0.1
## ✔ parsnip      1.1.1     ✔ yardstick    1.2.0
## ✔ recipes      1.0.9
## Warning: package 'scales' was built under R version 4.2.3
## Warning: package 'recipes' was built under R version 4.2.3
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## ✖ yardstick::accuracy() masks forecast::accuracy()
## ✖ infer::chisq_test()   masks rstatix::chisq_test()
## ✖ dplyr::combine()      masks gridExtra::combine()
## ✖ scales::discard()     masks purrr::discard()
## ✖ rstatix::filter()     masks dplyr::filter(), stats::filter()
## ✖ recipes::fixed()      masks stringr::fixed()
## ✖ dials::get_n()        masks rstatix::get_n()
## ✖ dplyr::lag()          masks stats::lag()
## ✖ yardstick::mae()      masks performance::mae()
## ✖ infer::prop_test()    masks rstatix::prop_test()
## ✖ yardstick::rmse()     masks performance::rmse()
## ✖ yardstick::spec()     masks readr::spec()
## ✖ recipes::step()       masks stats::step()
## ✖ infer::t_test()       masks rstatix::t_test()
## • Learn how to get started at https://www.tidymodels.org/start/
tidymodels_prefer()
library(beans)
library(corrr)

indept_corr <- indeptData %>%
  # select(-class) %>%      # drop non-numeric cols
  correlate() %>%         # generate a correlation matrix in data frame format
  rearrange() %>%         # group highly correlated variables together
  shave()                 # shave off the upper triangle
## Correlation computed with
## • Method: 'pearson'
## • Missing treated using: 'pairwise.complete.obs'
# plot the correlation matrix
indept_corr %>%
  rplot(print_cor=TRUE) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))

Principal Component Analysis

# https://www.rpubs.com/twyunting/PCA_in_the_tidyverse_Framework
# https://stackoverflow.com/questions/73786208/ggbiplot-how-to-change-the-colour-of-the-arrows-and-text-using-a-function-for

# PCA for business variables:
# customers,fulls,halfs,takeouts,liquors,sales
pca_bus <- df %>%
  filter(is_closed == FALSE) %>%
  select(c(customers,fulls,halfs,takeouts,liquors,sales)) %>%
  prcomp()
pca_bus
## Standard deviations (1, .., p=6):
## [1] 214.732100   7.765591   3.696578   3.444734   1.566496   1.184341
## 
## Rotation (n x k) = (6 x 6):
##                    PC1         PC2         PC3          PC4          PC5
## customers -0.040159987  0.65415860  0.53926876  0.003558498  0.060251895
## fulls     -0.029860294  0.54164943 -0.15786373  0.636260658  0.041233236
## halfs     -0.007547398  0.08289829  0.54937299 -0.489499360  0.050317942
## takeouts  -0.015212980 -0.51993282  0.60713716  0.592751376  0.096986947
## liquors   -0.003971133 -0.01596434 -0.11378519 -0.060061003  0.991282881
## sales     -0.998594698 -0.03514675 -0.02991606 -0.024260491 -0.009455986
##                     PC6
## customers  0.5253664932
## fulls     -0.5237131815
## halfs     -0.6701632001
## takeouts   0.0078888164
## liquors    0.0230916594
## sales     -0.0006150708
# Visualization ----
# the first principal direction (PC1) space
pca_bus %>%
  tidy(matrix = "loadings") %>%
  filter(PC == 1) %>%
  ggplot(aes(value, column)) +
  geom_col() +
  theme_bw()

# each pc space
pca_bus %>%
  tidy(matrix = "loadings") %>%
  ggplot(aes(value, column)) +
  geom_col() +
  facet_wrap(~PC)

# Variance explained
pca_bus %>%
  tidy(matrix = "pcs") %>%
  ggplot(aes(PC, percent)) +
  geom_col() +
  theme_bw() +
  scale_x_continuous(breaks = 1:8) +
  scale_y_continuous(
    labels = scales::percent_format(),
    expand = expansion(mult = c(0, 0.01))
  )

ggbiplot(pca_bus)

# PCA for weather terms:
# temperature, humidity, precipitation
pca_weather <- df %>%
  filter(is_closed == FALSE) %>%
  select(c(temp_c,humi_p,prcp_mm)) %>%
  prcomp()
pca_weather
## Standard deviations (1, .., p=3):
## [1] 11.97351  9.37176  1.99279
## 
## Rotation (n x k) = (3 x 3):
##                PC1        PC2         PC3
## temp_c  0.19339715  0.9809830  0.01643034
## humi_p  0.97919789 -0.1919432 -0.06579745
## prcp_mm 0.06139248 -0.0288136  0.99769772
# Visualization ----
# the first principal direction (PC1) space
pca_weather %>%
  tidy(matrix = "loadings") %>%
  filter(PC == 1) %>%
  ggplot(aes(value, column)) +
  geom_col() +
  theme_bw()

# each pc space
pca_weather %>%
  tidy(matrix = "loadings") %>%
  ggplot(aes(value, column)) +
  geom_col() +
  facet_wrap(~PC)

# Variance explained
pca_weather %>%
  tidy(matrix = "pcs") %>%
  ggplot(aes(PC, percent)) +
  geom_col() +
  theme_bw() +
  scale_x_continuous(breaks = 1:8) +
  scale_y_continuous(
    labels = scales::percent_format(),
    expand = expansion(mult = c(0, 0.01))
  )

ggbiplot(pca_weather)

Scatter Plot

FW with temp

# food waste and temperature ---------------------
scatter_waste_temp <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=temp_c, y=food_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
  limits = c(0, 7), expand = c(0, 0)) +
  scale_x_continuous(name = "Daily Temperature (Degree Celsius)",
  limits = c(-40, 15), expand = c(0, 0)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_temp

dens_temp <-
  ggplot(subset(df,is_closed==FALSE), aes(x = temp_c)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_temp

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_waste_temp <- 
  dens_temp +
  labs(title = "Scatter and Kernel Densities of Food Waste with Temperature (°C)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_temp + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_waste_temp

rm("dens_waste","dens_temp","scatter_waste_temp")

# solid food waste and temperature ---------------
scatter_waste_temp <-
  ggplot(subset(df,is_closed==FALSE),aes(x=temp_c, y=solid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
  limits = c(0, 3), expand = c(0, 0)) +
  scale_x_continuous(name = "Daily Temperature (Degree Celsius)",
  limits = c(-40, 15), expand = c(0, 0)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_temp

dens_temp <-
  ggplot(subset(df,is_closed==FALSE), aes(x = temp_c)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_temp

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_solid_waste_temp <- 
  dens_temp +
  labs(title = "Scatter and Kernel Densities of Solid Food Waste with Temperature (°C)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_temp + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_solid_waste_temp

rm("dens_waste","dens_temp","scatter_waste_temp")

# liquid food waste and temperature --------------
scatter_waste_temp <-
  ggplot(subset(df,is_closed==FALSE),aes(x=temp_c, y=liquid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
  limits = c(0, 5), expand = c(0, 0)) +
  scale_x_continuous(name = "Daily Temperature (Degree Celsius)",
  limits = c(-40, 15), expand = c(0, 0)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_temp

dens_temp <-
  ggplot(subset(df,is_closed==FALSE), aes(x = temp_c)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_temp

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_liquied_waste_temp <- 
  dens_temp +
  labs(title = "Scatter and Kernel Densities of Liquid Food Waste with Temperature (°C)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_temp + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_liquied_waste_temp

rm("dens_waste","dens_temp","scatter_waste_temp")

FW with humidity

# food waste and humidity ---------------------
scatter_waste_humi <-
  ggplot(subset(df,is_closed==FALSE),aes(x=humi_p, y=food_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
  limits = c(0, 7), expand = c(0, 0)) +
  scale_x_continuous(name = "Daily Humidity (Percent)",
  limits = c(50, 100), expand = c(0, 0)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
# scatter_waste_humi

dens_humi <-
  ggplot(subset(df,is_closed==FALSE), aes(x = humi_p)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_humi

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_waste_humi <- 
  dens_humi +
  labs(title = "Scatter and Kernel Densities of Food Waste with Humidity (%)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_humi + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_waste_humi

rm("dens_waste","dens_humi","scatter_waste_humi")

# solid food waste and humidity ---------------
scatter_waste_humi <-
  ggplot(subset(df,is_closed==FALSE),aes(x=humi_p, y=solid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
  limits = c(0, 3), expand = c(0, 0)) +
  scale_x_continuous(name = "Daily Humidity (Percent)",
  limits = c(50, 100), expand = c(0, 0)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_humi

dens_humi <-
  ggplot(subset(df,is_closed==FALSE), aes(x = humi_p)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_humi

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = solid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_solid_waste_humi <- 
  dens_humi +
  labs(title = "Scatter and Kernel Densities of Solid Food Waste with Humidity (%)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_humi + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_solid_waste_humi

rm("dens_waste","dens_humi","scatter_waste_humi")

# liquid food waste and humidity --------------
scatter_waste_humi <-
  ggplot(subset(df,is_closed==FALSE),aes(x=humi_p, y=liquid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
  limits = c(0, 5), expand = c(0, 0)) +
  scale_x_continuous(name = "Daily Humidity (Percent)",
  limits = c(50, 100), expand = c(0, 0)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_humi

dens_humi <-
  ggplot(subset(df,is_closed==FALSE), aes(x = humi_p)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_humi

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = liquid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_liquied_waste_humi <- 
  dens_humi +
  labs(title = "Scatter and Kernel Densities of Liquid Food Waste with Humidity (%)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_humi + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_liquied_waste_humi

rm("dens_waste","dens_humi","scatter_waste_temp")
## Warning in rm("dens_waste", "dens_humi", "scatter_waste_temp"): object
## 'scatter_waste_temp' not found

FW with precipitation

# food waste and humidity ------------------------
scatter_waste_precip <-
  ggplot(subset(df,is_closed==FALSE),aes(x=prcp_mm, y=food_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Precipitation (mm)",
                     limits = c(-15, 15), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,15), ylim=c(0,7)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_precip

dens_precip <-
  ggplot(subset(df,is_closed==FALSE), aes(x = prcp_mm)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_precip

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_precip <- 
  dens_precip +
  labs(title = "Scatter and Kernel Densities of Food Waste and Precipitation (mm)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_precip + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_precip

# Solid food waste and humidity ------------------------
scatter_waste_precip <-
  ggplot(subset(df,is_closed==FALSE),aes(x=prcp_mm, y=solid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Solid Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Precipitation (mm)",
                     limits = c(-15, 15), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,15), ylim=c(0,3)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_precip

dens_precip <-
  ggplot(subset(df,is_closed==FALSE), aes(x = prcp_mm)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_precip

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = solid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_solid_precip <- 
  dens_precip +
  labs(title = "Scatter and Kernel Densities of Solid Food Waste and Precipitation (mm)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_precip + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_solid_precip

# Liquid food waste and humidity ------------------------
scatter_waste_precip <-
  ggplot(subset(df,is_closed==FALSE),aes(x=prcp_mm, y=liquid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Solid Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Precipitation (mm)",
                     limits = c(-15, 15), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,15), ylim=c(0,6)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_precip

dens_precip <-
  ggplot(subset(df,is_closed==FALSE), aes(x = prcp_mm)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_precip

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = liquid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_liquid_precip <- 
  dens_precip +
  labs(title = "Scatter and Kernel Densities of Liquid Food Waste and Precipitation (mm)") +
  plot_spacer() + # library(patchwork)
  scatter_waste_precip + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_liquid_precip

rm("dens_waste","dens_precip","scatter_waste_precip")

FW with customers

# food waste and customer ------------------------
scatter_waste_customer <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=customers, y=food_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Number of Customers",
                     limits = c(0, 60), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,50), ylim=c(0,7)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_customer

dens_customer <-
  ggplot(subset(df,is_closed==FALSE), aes(x = customers)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_customer

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_customer <- 
  dens_customer +
  labs(title = "Scatter and Kernel Densities of Food Waste and Customers") +
  plot_spacer() + # library(patchwork)
  scatter_waste_customer + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_customer

# solid food waste and customer ------------------------
scatter_waste_customer <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=customers, y=solid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Solid Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Number of Customers",
                     limits = c(0, 60), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,50), ylim=c(0,3)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_customer

dens_customer <-
  ggplot(subset(df,is_closed==FALSE), aes(x = customers)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_customer

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = solid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_solid_customer <- 
  dens_customer +
  labs(title = "Scatter and Kernel Densities of Solid Food Waste and Customers") +
  plot_spacer() + # library(patchwork)
  scatter_waste_customer + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_solid_customer

# liquid food waste and customer ------------------------
scatter_waste_customer <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=customers, y=liquid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Liquid Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Number of Customers",
                     limits = c(0, 60), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,50), ylim=c(0,6)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_customer

dens_customer <-
  ggplot(subset(df,is_closed==FALSE), aes(x = customers)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_customer

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), 
         aes(x = liquid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_liquid_customer <- 
  dens_customer +
  labs(title = "Scatter and Kernel Densities of Liquid Food Waste and Customers") +
  plot_spacer() + # library(patchwork)
  scatter_waste_customer + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_liquid_customer

rm("dens_waste","dens_customer","scatter_waste_customer")

FW with sales

# food waste and sales ------------------------
scatter_waste_sales <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=sales, y=food_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Sales (CAD)",
                     limits = c(0, 1300), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,1300), ylim=c(0,7)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_sales

dens_sales <-
  ggplot(subset(df,is_closed==FALSE), aes(x = sales)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_sales

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = food_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_sales <- 
  dens_sales +
  labs(title = "Scatter and Kernel Densities of Food Waste and Customers") +
  plot_spacer() + # library(patchwork)
  scatter_waste_sales + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_sales

# solid food waste and sales ------------------------
scatter_waste_sales <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=sales, y=solid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Sales (CAD)",
                     limits = c(0, 1300), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,1300), ylim=c(0,4)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_sales

dens_sales <-
  ggplot(subset(df,is_closed==FALSE), aes(x = sales)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_sales

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = solid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_solid_sales <- 
  dens_sales +
  labs(title = "Scatter and Kernel Densities of Solid Food Waste and Customers") +
  plot_spacer() + # library(patchwork)
  scatter_waste_sales + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_solid_sales

# solid food waste and sales ------------------------
scatter_waste_sales <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=sales, y=liquid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Sales (CAD)",
                     limits = c(0, 1300), expand = c(0.05, 0)) +
  coord_cartesian(xlim=c(0,1300), ylim=c(0,3)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_sales

dens_sales <-
  ggplot(subset(df,is_closed==FALSE), aes(x = sales)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_sales

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), aes(x = liquid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_liquid_sales <- 
  dens_sales +
  labs(title = "Scatter and Kernel Densities of Liquid Food Waste and Customers") +
  plot_spacer() + # library(patchwork)
  scatter_waste_sales + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_liquid_sales

rm("dens_waste","dens_sales","scatter_waste_sales")

FW with liquor

# food waste and liquor ------------------------
scatter_waste_liquor <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=liquors, y=food_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Liquor Sold",
                     limits = c(0, 10), expand = c(0.01, 0)) +
  coord_cartesian(xlim=c(0,8), ylim=c(0,7)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_liquor

dens_liquor <-
  ggplot(subset(df,is_closed==FALSE), aes(x = liquors)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_liquor

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), 
         aes(x = food_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_dens_liquor <- 
  dens_liquor +
  labs(title = "Scatter and Kernel Densities of Food Waste and Liquor") +
  plot_spacer() + # library(patchwork)
  scatter_waste_liquor + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_dens_liquor

# solid food waste and liquor ------------------------
scatter_waste_liquor <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=liquors, y=solid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Solid Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Liquor Sold",
                     limits = c(0, 10), expand = c(0.01, 0)) +
  coord_cartesian(xlim=c(0,8), ylim=c(0,3)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_liquor

dens_liquor <-
  ggplot(subset(df,is_closed==FALSE), aes(x = liquors)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_liquor

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), 
         aes(x = solid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_solid_liquor <- 
  dens_liquor +
  labs(title = "Scatter and Kernel Densities of Solid Food Waste and Liquor") +
  plot_spacer() + # library(patchwork)
  scatter_waste_liquor + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_solid_liquor

# liquid food waste and liquor ------------------------
scatter_waste_liquor <-
  ggplot(subset(df,is_closed==FALSE),
         aes(x=liquors, y=liquid_waste_kg)) +
  geom_point(size = 2) +
  geom_point(shape = 1, color = "black", size = 2) +
  geom_smooth(method="lm", formula = y ~ x, fullrange=TRUE) +
  geom_rug() +
  scale_y_continuous(name = "Daily Liquid Food Waste (kg)",
                     limits = c(-10, 10), expand = c(0.05, 0)) +
  scale_x_continuous(name = "Daily Liquor Sold",
                     limits = c(0, 10), expand = c(0.01, 0)) +
  coord_cartesian(xlim=c(0,8), ylim=c(0,3)) +
  theme_pubr() +
  theme(legend.position = c(0.15, 0.9))
#scatter_waste_liquor

dens_liquor <-
  ggplot(subset(df,is_closed==FALSE), aes(x = liquors)) +
  geom_density(color="black", fill="grey") +
  scale_fill_grey() +
  theme_void() +
  theme(legend.position = "none")
#dens_liquor

dens_waste <-
  ggplot(subset(df,is_closed==FALSE), 
         aes(x = liquid_waste_kg), fill = "dark") +
  geom_density(color="black", fill="grey") +
  theme_void() +
  theme(legend.position = "none") +
  coord_flip()
#dens_waste

scatter_liquid_liquor <- 
  dens_liquor +
  labs(title = "Scatter and Kernel Densities of Food Waste and Liquor") +
  plot_spacer() + # library(patchwork)
  scatter_waste_liquor + dens_waste +
  plot_layout(ncol = 2, nrow = 2, widths = c(4, 1), heights = c(1, 4))

scatter_liquid_liquor

rm("dens_waste","dens_liquor","scatter_waste_liquor")

Correlogram

Cross-Correlation

ccf_fl_all <- 
  ggCcf(df$food_loss_kg,df$food_waste_kg) +
  labs(title = "Cross Corr Plot: Food Loss vs. All Food Waste")
ccf_fl_liq <-
  ggCcf(df$food_loss_kg,df$liquid_waste_kg) +
  labs(title = "Cross Corr Plot: Food Loss vs. Liquid Food Waste")
ccf_fl_sol <-
  ggCcf(df$food_loss_kg,df$solid_waste_kg) +
  labs(title = "Cross Corr Plot: Food Loss vs. Solid Food Waste")
ccf_all_liq <-
  ggCcf(df$food_waste_kg,df$liquid_waste_kg) +
  labs(title = "Cross Corr Plot: All Food Waste vs. Liquid Food Waste")
ccf_all_sol <-
  ggCcf(df$food_waste_kg,df$solid_waste_kg) +
  labs(title = "Cross Corr Plot: All Food Waste vs. Solid Food Waste")
ccf_liq_sol <-
  ggCcf(df$liquid_waste_kg,df$solid_waste_kg) +
  labs(title = "Cross Corr Plot: liquid Food Waste vs. Solid Food Waste")

grid.arrange(ccf_fl_all,ccf_fl_liq,ccf_fl_sol,
             ccf_all_liq,ccf_all_sol,ccf_liq_sol)